package org.netconsole.dao;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import org.netconsole.model.Processus;

public class ProcessusDAOImpl implements ProcessusDAO {
	
    private SessionFactory sf;

    public ProcessusDAOImpl(SessionFactory sf){
            this.sf = sf;
    }

    public ProcessusDAOImpl() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Processus insertProcessus(Processus p) {
        try{
            Session session = sf.openSession();
            session.beginTransaction();
            session.save(p);
            session.getTransaction().commit();
        } catch (Exception e){

        }

        return p;
    }

    @Override
    public List<Processus> listProcessusById(long inf_id) {
        List<Processus> lst = new ArrayList<Processus>();
        Session session = sf.openSession();
        lst = session.createQuery("from Processus where inf_id=:inf_id").setString("inf_id", Long.toString(inf_id)).list();
                    if(lst != null){
                    System.out.println("process Retrieved from DB::"+ lst);
            }
        session.close();
        return lst;
    }

}
